﻿using Authorization.Center.Dto;
using AutoMapper;
using MediatR;
using Microsoft.EntityFrameworkCore;
using S.Archives.Api.Application.Command;
using S.Archives.Infrstructre.InterFace;

namespace S.Archives.Api.Application.CommandHandlers
{
    public class ReproductiveStateEditCommandHandler : IRequestHandler<ReproductiveStateEditCommand, bool>
    {
        private readonly ISheepFileRepository sheepFileRepository;
        private readonly IMapper mapper;
        public ReproductiveStateEditCommandHandler(ISheepFileRepository sheepFileRepository, IMapper mapper)
        {
            this.sheepFileRepository = sheepFileRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 修改繁殖状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        public async Task<bool> Handle(ReproductiveStateEditCommand request, CancellationToken cancellationToken)
        {
           var sheep= sheepFileRepository.GetAll().FirstOrDefaultAsync(x=>x.EarTag==request.EarTag).Result;
            sheep.ReproductiveState = request.ReproductiveState;
            sheep.ReproductiveStateDate = request.ReproductiveStateDate;       
            return  sheepFileRepository.Update(sheep);


        }
    }
}
